/*
Date:20220224 20:49PM
key:1.双指针+集合
*/
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if(s.size()<2)
        {
            return s.size();
        }
        int l=0,r=0,Max=0;
        unordered_set<char>Set;
        while(r<s.size())
        {
            //cout<<s[r]<<" ";
            if(Set.count(s[r])==0)
            {
                Set.insert(s[r]);
                r++;
                Max=max(Max,r-l);
            }
            else
            {
                Max=max(Max,r-l);
                //不同就往前走
                while(s[l]!=s[r])
                {
                    Set.erase(s[l]);
                    l++;
                }
                l++;
                r++;
            }
            //r++;
        }
        return Max;
    }
};